package com.kuang.single;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author Administrator
 * @date 2021/5/27 16:28
 * Description:枚举本身也是一个class类
 */
public enum EnumSingle {
    INSTANCE; // 该对象全局唯一

    public EnumSingle getInstance() {
        return INSTANCE;
    }
}

class Test{
    public static void main(String[] args) throws Exception {
        EnumSingle instance1 = EnumSingle.INSTANCE;
        Constructor<EnumSingle> constructor = EnumSingle.class
                .getDeclaredConstructor(String.class, int.class);
        constructor.setAccessible(true);
        EnumSingle instance2 = constructor.newInstance("s", 1);
        System.out.println(instance1==instance2);
    }
}